
// <copyright file="PleaseWaitForm.cs" company="Subhadra Software Solutions">
//   
// </copyright>
// <summary>
//   Class PleaseWaitForm.
// </summary>

namespace SubhadraSolutions.Sharp.Utils.Windows.Forms
{
    using System;
    using System.Threading;
    using System.Windows.Forms;

    /// <summary>
    ///     Class PleaseWaitForm.
    /// </summary>
    public partial class PleaseWaitForm : Form
    {
        #region Fields

        /// <summary>
        ///     The _handle
        /// </summary>
        private readonly WaitHandle _handle;

        #endregion Fields

        #region Constructors and Finalizers

        /// <summary>
        /// Initializes a new instance of the <see cref="PleaseWaitForm"/> class.
        /// </summary>
        /// <param name="handle">
        /// The handle.
        /// </param>
        public PleaseWaitForm(WaitHandle handle)
        {
            this.InitializeComponent();
            this._handle = handle;
            this.timer1.Enabled = true;
        }

        #endregion Constructors and Finalizers

        #region Public Properties

        /// <summary>
        ///     Gets or sets the status message.
        /// </summary>
        /// <value>The status message.</value>
        public string StatusMessage
        {
            get
            {
                return this.statusMessageLabel.Text;
            }

            set
            {
                this.statusMessageLabel.Text = value;
            }
        }

        #endregion Public Properties

        #region Methods

        /// <summary>
        /// Handles the Tick event of the timer1 control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="EventArgs"/> instance containing the event data.
        /// </param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (this._handle.WaitOne(1))
            {
                this.Close();
            }
        }

        #endregion Methods
    }
}
